<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    <title>巡检任务执行与回执 >> 回执录入</title>
    <!-- BOOTSTRAP STYLES-->
    <link href="../assets/css/bootstrap.css" rel="stylesheet"/>
    <!-- FONTAWESOME STYLES-->
    <link href="../assets/css/font-awesome.css" rel="stylesheet"/>
    <!--CUSTOM BASIC STYLES-->
    <link href="../assets/css/basic.css" rel="stylesheet"/>
    <!--CUSTOM MAIN STYLES-->
    <link href="../assets/css/custom.css" rel="stylesheet"/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
    <!-- GOOGLE FONTS-->
    <link href='https://fonts.googleapis.com/css?family=Open+Sans' rel='stylesheet' type='text/css'/>
</head>
<body>
<div id="wrapper">
    <div id="page-inner">
        <div class="row">
            <div class="col-md-12 col-sm-12 col-xs-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        巡检任务执行与回执 >> 回执录入
                    </div>
                    <div class="panel-body">
                        <div role="form">

                            <div>
                                <div style="width: 20%;height: 585px; border: 1px solid slategray;padding: 20px 6px; float: left;">
                                    <div class="table-responsive">
                                        <table class="table table-striped table-bordered table-hover"
                                               style="text-align: center ;overflow-scrolling: auto">
                                            <thead>
                                            <tr>
                                                <th>
                                                    <input disabled class="btn btn-danger col-md-12" id="linecodename"/>
                                                </th>
                                            </tr>
                                            </thead>
                                            <tbody id="polecodename">
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div style="width: 80%; height: 585px; border: 1px solid slategray;padding: 20px 10px;float: left;"
                                     class="form-horizontal" role="form">
                                    <div class="form-group">
                                        <div class="col-md-2">
                                            <label for="lineCodeDelic">线路编码*</label>
                                            <input type="text" class="form-control" value="" id="lineCodeDelic"
                                                   disabled>
                                        </div>
                                        <div class="col-md-2">
                                            <label for="poleCode">杆塔编码*</label>
                                            <input type="text" class="form-control" id="poleCode" disabled>
                                        </div>

                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-2">
                                            <label for="bugTypeName">缺陷类型*</label>
                                            <select class="form-control" id="bugTypeName" name="bugTypeName">
                                                <option value="">--请选择--</option>
                                                <option value="叉粱断裂">叉粱断裂</option>
                                                <option value="拦河线断裂">拦河线断裂</option>
                                                <option value="绝缘子爆破">绝缘子爆破</option>
                                                <option value="杆塔倾斜">杆塔倾斜</option>
                                                <option value="吊杆变形">吊杆变形</option>
                                                <option value="其他">其他</option>

                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-2">
                                            <label for="bugLevelName">缺陷级别*</label>
                                            <select class="form-control" id="bugLevelName" name="bugLevelName">
                                                <option value="">--请选择--</option>
                                                <option value="一般">一般</option>
                                                <option value="严重">严重</option>
                                                <option value="紧急">紧急</option>
                                            </select>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-2">
                                            <label for="intactRate">完好率*</label>
                                            <input type="text" class="form-control" id="intactRate">
                                        </div>
                                    </div>

                                    <div class="form-group">
                                        <div class="col-md-2">
                                            <label for="discovererName">缺陷发现人*</label>
                                            <input type="text" class="form-control" id="discovererName" disabled>
                                        </div>
                                        <div class="col-md-2">
                                            <label for="discoverTime">发现时间*</label>
                                            <input type="text" class="form-control" id="discoverTime" disabled>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-md-6">
                                            <label for="bugDesc">缺陷描述*</label>
                                            <textarea class="form-control" rows="3" id="bugDesc"></textarea>
                                        </div>
                                    </div>
                                    <input type="hidden" id="poleid"/>

                                </div>
                                <div style="float: left;width: 100%; margin: 10px auto">
                                    <div class="form-group">
                                        <div class="col-sm-2">
                                            <button class="btn btn-danger col-sm-12 " id="UploadReceipt">上传回执</button>
                                        </div>
                                        <div class="col-sm-1">
                                            <button class="btn btn-info col-sm-12" id="save">保存</button>
                                        </div>
                                        <div class="col-sm-1">
                                            <button class="btn btn-info col-sm-12" id="returngo">返回</button>
                                        </div>
                                    </div>
                                </div>
                            </div>


                        </div>

                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="../assets/js/jquery.min.js"></script>
<!-- BOOTSTRAP SCRIPTS -->
<script src="../assets/js/bootstrap.min.js"></script>
<script>
    $(function () {
        getTimeAndInit();
        getlineAndPole();
        $("#UploadReceipt").click(function () {
            alert("已上传");
            window.location.href = 'ExecutionAndReceipt.html';
        });
        $("#save").click(function () {
            saveInspecDeail();
        });
        $("#returngo").click(function () {
            window.history.go(-1);
        })
    })

    //获取当前时间和当前登录的用户
    function getTimeAndInit() {
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth() + 1;
        var day = date.getDate();
        var time = year + "-" + month + "-" + day;
        $("#discoverTime").val(time);
        var userName = sessionStorage.getItem("userName");
        $("#discovererName").val(userName);

        var lineCode = sessionStorage.getItem("lineCodes");
        $("#lineCodeDelic").val(lineCode);
    }


    //获取线路以及该线路下的所有塔
    function getlineAndPole() {
        var lineCode = sessionStorage.getItem("lineCodes");
        $.ajax({
            url: "http://localhost:8080/poleInfo/" + lineCode,
            type: 'GET',
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                var list = data.obj;
                for (var i = 0; i < list.length; i++) {
                    var lineCode = list[i].lineCode.trim();
                    var poleid = list[i].id;
                    var lineName = list[i].lineName;
                    var poleCode = list[i].poleCode.trim();
                    $("#linecodename").val(lineName);
                    $("#poleid").val(poleid);
                    var tr = "<tr>" +
                        "<td >" +
                        "<a  class='btn btn-success polecodes' href='javascript:getInspecDetail(\"" + poleCode + "\"," + i + ",\"" + lineCode + "\")'>" + poleCode + "</a>" +
                        "</td>" +
                        "</tr>"
                    $("#polecodename").append(tr);
                }
            }
        })
    }


    function getInspecDetail(poleCode, i, lineCode) {
        $.ajax({
            url: "http://localhost:8080/inspectaskdetail/" + lineCode,
            type: 'GET',
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                $("#poleCode").val(poleCode);
                var list = data.obj;
                for (var j = 0; j < list.length; j++) {
                    var poleCoded = list[j].poleCode.trim();
                    if (poleCoded != poleCode) {
                        $("#UploadReceipt").removeClass("hidden");
                        $("#save").removeClass("hidden");
                    } else if (poleCoded == poleCode) {
                        $("#UploadReceipt").addClass("hidden");
                        $("#save").addClass("hidden");
                        $("#polecodename  a").eq(i).addClass("btn-danger");
                        break;
                    }
                }
            },
            error: function () {
                alert(error)
            }
        })
    }

    function saveInspecDeail() {
        var lineCodeDelic = $("#lineCodeDelic").val().trim();
        var poleCode = $("#poleCode").val().trim();
        var bugTypeName = $("#bugTypeName").val().trim();
        var bugLevelName = $("#bugLevelName").val().trim();
        var intactRate = $("#intactRate").val().trim();
        var discovererName = $("#discovererName").val().trim();
        var discoverTime = $("#discoverTime").val().trim();
        var bugDesc = $("#bugDesc").val().trim();
        var inspeId = sessionStorage.getItem("inspeId");
        var poleid = $("#poleid").val().trim();
        var lineName = $("#linecodename").val().trim();

        var addInspecDeailJson = {
            "taskId": inspeId,
            "poleId": poleid,
            "lineCode": lineCodeDelic,
            "lineName": lineName,
            "poleCode": poleCode,
            "bugTypeName": bugTypeName,
            "bugLevelName": bugLevelName,
            "intactRate": intactRate,
            "discovererName": discovererName,
            "discoverTime": discoverTime,
            "creationTime": discoverTime,
            "lastUpdateTime": discoverTime,
            "createdBy": discovererName,
            "bugDesc": bugDesc
        };
        $.ajax({
            url: 'http://localhost:8080/inspectaskdetail/',
            type: 'POST',
            data: JSON.stringify(addInspecDeailJson),
            dataType: "json",
            contentType: "application/json;charset=UTF-8",
            success: function (data) {
                alert("已经保存");
            },
            error: function () {
            }
        })
    }


</script>

</body>
</html>
